//
//  ZJProjectInformationVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/27.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJProjectInformationVC.h"
#import "ZJProjectImgVC.h"
#import "ZJProjectInfoVC.h"
#import "ZJCommentVC.h"
#import "ZJAroundVC.h"
#import "ZJCollFooterView.h"

#import "ZJCollectionHeaderView.h"
#import "ZJCollectionFooterView.h"
#import "ZJHomeCollectionCell.h"
#import "ZJRoomModelVC.h"
#import "ZJHomeModel.h"
static NSString *headerViewIdentifier = @"hederview";
@interface ZJProjectInformationVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIImageView *topBgImg;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (strong, nonatomic) ZJHomeModel * model;
@property (strong, nonatomic) UIView *cellBgView;

@property (strong, nonatomic) UIToolbar *toolbar;

@property (strong, nonatomic) ZJCollFooterView * ProjectBottomView;
@end

@implementation ZJProjectInformationVC
-(ZJCollFooterView *)ProjectBottomView{
if (!_ProjectBottomView) {
    _ProjectBottomView = [[[NSBundle mainBundle] loadNibNamed:@"ZJCollFooterView" owner:self options:nil] lastObject];

}
    return _ProjectBottomView;
}
-(UIView *)cellBgView{
    if (!_cellBgView) {
        _cellBgView = [[UIView alloc]init];
        _cellBgView.backgroundColor = [UIColor clearColor];
        _cellBgView.frame = CGRectZero;
    }
    return _cellBgView;
}

-(UIToolbar *)toolbar{
    if (!_toolbar) {
        _toolbar = [[UIToolbar alloc] init];
        _toolbar.barStyle = UIBarStyleBlackTranslucent;
    }
    return _toolbar;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
//    self.navigationController.navigationBarHidden = YES;
}
- (IBAction)goBack:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

-(ZJHomeModel *)model{
    if (!_model) {
        _model = [[ZJHomeModel alloc]init];
        //测试数据
        _model.imagePath =  @"zwt_b";
        _model.homeImage = @[@"lpxx_icon_lpzs",@"lpxx_icon_360",@"lpxx_icon_video",@"lpxx_icon_pic",@"lpxx_icon_ybj",@"lpxx_icon_zbpt"];
        _model.homeTopText = @[@"楼盘综述",@"360度",@"视频",@"图片",@"样板间",@"周边配套"];
        _model.homeTopSmallText = @[@"Building Were",@"360 Degrees",@"Video",@"Picture",@"Mock-up",@"Surrounding Facility"];
    }
    return _model;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.ProjectBottomView.bottom.layer.masksToBounds = YES;
    self.ProjectBottomView.bottom.layer.cornerRadius = 5.0f;
    self.ProjectBottomView.contentCount.text = self.prModel.comment_total;
    self.ProjectBottomView.bottom.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:0.3f];

    [self.ProjectBottomView.commentBtn addTarget:self action:@selector(comment) forControlEvents:UIControlEventTouchUpInside];
    [self setupCollectionLayout];
}

-(void)setupCollectionLayout{
//    self.collectionView.backgroundColor = [UIColor orangeColor];
    float colHeight = self.view.height - 98 - 66 - 70;
    float colWidth = self.view.width - 104;
    if (SCREEN_WIDTH >= 414) {
        colWidth = self.view.width - 114;
    }
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    //设置布局方向为垂直流布局
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //设置每个item的大小
    layout.itemSize = CGSizeMake(colWidth / 2, (colHeight - 20) * 0.3);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.headerReferenceSize =CGSizeMake(self.collectionView.width,80);
    layout.footerReferenceSize =CGSizeMake(self.collectionView.width,66);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    
    self.collectionView.collectionViewLayout = layout;
}
#pragma mark -UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.homeImage.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ZJHomeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeCollectionCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:0.3f];
    cell.imgview.image = [UIImage imageNamed:self.model.homeImage[indexPath.row]];
    cell.topText.text = self.model.homeTopText[indexPath.row];
    cell.topText.font = [UIFont systemFontOfSize:[Utils iphone5AutoScaleW:12.0f]];
    cell.smallText.text = self.model.homeTopSmallText[indexPath.row];
    cell.smallText.font = [UIFont systemFontOfSize:[Utils iphone5AutoScaleW:10.0f]];
    cell.layer.masksToBounds = YES;
    cell.layer.cornerRadius = 5.0f;
    return cell;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            ZJProjectInfoVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJProjectInfoVC"];
            vc.model = self.prModel;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 1:
        {
            if ([self.prModel.house_vr integerValue] != 1) {
                [HUD showMsg:@"暂无vr视频提供"];
            }else{
                ZJActivityVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJActivityVC"];
                vc.urlStr = self.prModel.vr_url;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 2:
        {
            ZJProjectImgVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJProjectImgVC"];
            vc.roomType = @"视频";
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 3:
        {
            ZJProjectImgVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJProjectImgVC"];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 4:
        {
            ZJRoomModelVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJRoomModelVC"];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 5:
        {
            ZJAroundVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJAroundVC"];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;

            
        default:
            break;
    }
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  return 10;
    
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  return 0;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
        
        NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld", (long)[indexPath section]];
        [self.collectionView registerClass:[ZJCollectionHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier];
        ZJCollectionHeaderView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
        
        if (header.subviews.count <= 0) {
            UIImageView *imgv = [[UIImageView alloc]init];
            
            header.imgV = imgv;
#warning 项目改动
            if ([allConstProjectid integerValue] == 7) {
                header.imgV.image = [UIImage imageNamed:@"xzxm_logo_nbxz"];
            }else{
                header.imgV.image = [UIImage imageNamed:@"xzxm_logo_xgxz"];
            }
            
        }
        return header;
        
    }
    if ([kind isEqualToString:UICollectionElementKindSectionFooter]){
        
        NSString *CellIdentifier = [NSString stringWithFormat:@"CellFooter%ld", (long)[indexPath section]];
        [self.collectionView registerClass:[ZJCollectionFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:CellIdentifier];
        ZJCollectionFooterView *footer=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
        
        if (footer.subviews.count <= 0) {
            self.ProjectBottomView.frame = CGRectMake(10, 0, self.collectionView.width - 20, 66);
            [footer addSubview:self.ProjectBottomView];
            
        }
        return footer;
        
    }
        return nil;

    
//    return reusableview;
}

-(void)comment{
    ZJCommentVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJCommentVC"];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
